package com.bw.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.bw.finance.eneity.TbRoleMenu;
import com.bw.finance.mapper.TbRoleMenuMapper;
import com.bw.finance.service.ITbRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lizhengqian
 * @since 2020-05-09
 */
@Service
public class TbRoleMenuServiceImpl extends ServiceImpl<TbRoleMenuMapper, TbRoleMenu> implements ITbRoleMenuService {
    @Autowired
    private TbRoleMenuMapper mapper;
    @Override
    public void add(Long roleId, Long[] menuIds) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("ROLE_ID",roleId);
        mapper.delete(queryWrapper);
        List<TbRoleMenu> list=new ArrayList<>();
        for (int i=1;i<menuIds.length;i++){
            TbRoleMenu tbRoleMenu=new TbRoleMenu();
            tbRoleMenu.setRoleId(roleId);
            tbRoleMenu.setMenuId(menuIds[i]);
            list.add(tbRoleMenu);
        }
        this.saveBatch(list);
    }
}
